package com.xiaoyi.library.controller;

import com.xiaoyi.library.pojo.User;
import com.xiaoyi.library.service.UserService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.ModelMap;
import org.springframework.web.bind.annotation.*;

@RestController
@CrossOrigin
public class UserController {

    private UserService userService;

    @Autowired
    public UserController(UserService userService) {
        this.userService = userService;
    }


    @PostMapping("/register")
    public boolean addUser(@RequestBody User user) {
        System.out.println(user);
        System.out.println("注册成功");
        return userService.insertUser(user);
    }
    @PostMapping("/login")
    public boolean login(@RequestBody User user) {
        System.out.println(user.getUser_name());
        boolean result = userService.findByUsernameAndPassword(user.getUser_name(), user.getUser_password());
        if (result) {
            System.out.println("登录成功");
            return true;
        } else {
            return false;
        }
    }
}

